package logic

import (
	"context"
	"rent-ease/models/mysql"

	"rent-ease/rentrpc/internal/svc"
	"rent-ease/rentrpc/rentrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RentShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRentShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RentShowLogic {
	return &RentShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *RentShowLogic) RentShow(in *rentrpc.RentShowRequest) (*rentrpc.RentShowResponse, error) {
	// todo: add your logic here and delete this line

	var rent mysql.Rent

	if err := rent.RentFindById(mysql.DB, in.RentId); err != nil {
		return nil, err
	}

	return &rentrpc.RentShowResponse{
		Name:    rent.Name,
		Address: rent.Address,
		Price:   float32(rent.Price),
		RentId:  int64(rent.ID),
	}, nil
}
